{% extends "base.html" %}
{% block page_title %}Routing Anomalies{% endblock %}
{% block content %}
  <div id="featured-projects">
    <h4>Latest Anomalous BGP UPDATEs (including hijacking alarms)</h4>
    <div>
      <form action="/anomalies/" method="post">{% csrf_token %}
        <table><tr>
          <td>
            <input type="submit" value="filter">
          </td>
          <td>
            #anomalies: {{ form.topx }}
            {% if form.topx.errors %}
              <font color="red">int: [1, 199]</font>
            {% endif %}
          </td>
          <td>
            prefix: {{ form.prefix }}
            {% if form.prefix.errors %}
              <font color="red">
                IPv4: A.B.C.D/M (0&le;M&le;32),
                IPv6: A:B:C::/M (0&le;M&le;128)
              </font>
            {% else %}
              <font color="#aaa">
                (IPv4: A.B.C.D/M 0&le;M&le;32, IPv6: A:B:C::/M 0&le;M&le;128)
              </font>
            {% endif %}
          </td>
          <td>
            AS: {{ form.AS }}
            {% if form.AS.errors %}
              <font color="red">int: [1, 2^32]</font>
            {% else %}
              <font color="#aaa">
                (AS Number)
              </font>
            {% endif %}
          </td><!--
          <td>
            RPKI: {{ form.rpki }}<br/>
            {% if form.rpki.errors %}
              <font color="red">Y/N</font>
            {% endif %}
          </td>-->
        </tr></table>
      </form>
    </div>
    <br/>
    <table>
      <tr><td>
        <table><head><tr><th>#</th></head>
        <body>{% for anomaly in anomalies %}<tr><td align=right>{{ forloop.counter }}</td></tr>{% endfor %}</body></table>
     </td>
     <td>
        <table id="anomalies" class="tablesorter">
          <thead>
          <tr>
            <th>Time (UTC)</th>
            <!--<th>Timestamp</th>-->
            <th>IP Prefix</th>
            <th>CC</th>
            <th>Suspicious AS Path Segment</th>
            <th>Max Fing.</th>
            <th>Min Fing.</th>
            <th>Avg Fing. [-1, 1]</th>
            <!--<th>RPKI</th>-->
            <th>Detail</th>
          </tr>
          </thead>
          <tbody>
          {% for anomaly in anomalies %}
          <tr>
            <td>{{ anomaly.1 }}</td>
            <!--<td>{{ anomaly.0.time }}</td>-->
            <td>
              <a href="http://bgp.he.net/net/{{ anomaly.0.prefix_dec }}" target="_blank">{{ anomaly.0.prefix_dec }}</a>
              {% if anomaly.8 %}<a href="/fingerprints/{{ anomaly.0.alarm_id }}#prefixes" target="_blank">+{{ anomaly.8 }}</a>
              {% endif %}
            </td>
            <td>{{ anomaly.9 }}</td>
            <td align=right>
              {% if anomaly.0.homeas %}
              Origin change: {% if anomaly.0.oldhomeas %}<a href="http://bgp.he.net/AS{{ anomaly.0.oldhomeas }}#_prefixes" target="_blank">AS{{ anomaly.0.oldhomeas }}</a>{% else %}N/A{% endif %}
              -&gt; <a href="http://bgp.he.net/AS{{ anomaly.0.homeas }}#_prefixes" target="_blank">AS{{ anomaly.0.homeas }}</a>
              {% else %}
                {% if anomaly.5 %}AS triple:
              <a href="http://bgp.he.net/AS{{ anomaly.5 }}#_graph4" target="_blank">AS{{ anomaly.5 }}</a>
                {% else %}AS edge:
                {% endif %}
              <a href="http://bgp.he.net/AS{{ anomaly.6 }}#_graph4" target="_blank">AS{{ anomaly.6 }}</a>
              <a href="http://bgp.he.net/AS{{ anomaly.7 }}#_graph4" target="_blank">AS{{ anomaly.7 }}</a>
              {% endif %}
            </td>
            <td align=right>{{ anomaly.2 }}</td>
            <td align=right>{{ anomaly.3 }}</td>
            <td align=right>{{ anomaly.4 }}</td>
            <!--<td align=right>{{ anomaly.0.rpki }}</td>-->
            <td><a href="/fingerprints/{{ anomaly.0.alarm_id }}" target="_blank">>>></a></td>
          </tr>
          {% endfor %}
          </tbody>
        </table>
      </td></tr>
    </table>
  </div><!--end featured-projects-->
{% endblock %}
{% block js_script %}
  <script src="/static/jquery-latest.js"></script>
  <script type="text/javascript" src="/static/jquery.tablesorter.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){ 
        $("#anomalies").tablesorter();
      }
    );
  </script>
{% endblock %}
